<template>
<!-- 打款审核新增页面弹框 -->
  <div>
    <div style="height:300px">
      <FormPanel
        ref="from"
        :list="initForm"
        :cols="3"
        formType="add"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
        @formChange="changeHandle"
      />
    </div>
    <div class="dialogBottmView">
      <el-button @click="closeDialog('closeDialog')">关 闭</el-button>
      <el-button :loading="loadingFlag1" @click="saveDialog(30081001)" type="primary">保 存</el-button>
      <!-- <el-button :loading="loadingFlag2" @click="saveDialog('30081002')" type="primary">提 交</el-button> -->
    </div>
  </div>
</template>
<script>

import { auditAdd } from '@/api/partsmanage/financialManagement/capitalAccount/index';
import { notifyAction } from '@/utils';
import { dictionary } from '@/utils/dictMixin';
import { plus } from '@/utils/validate';

export default {
  props: {
  },
  data(){
    return{
      initForm:this.createdFrom(),
      loadingFlag1:false,
      loadingFlag2:false,
    }
  },
  mixins:[dictionary],
  methods:{
    changeHandle(val){
      console.log(val)
    },
    async saveDialog(val){//保存或提交
        if(this.loadingFlag1 || this.loadingFlag2){
            return notifyAction('已有操作在进行中请稍后!', 'warning');
        }
        //表单校验
        let [err, data] = await this.$refs.from.GET_FORM_DATA();
        if(err) return;
        data.paymentStatus = val;
        //add数据
        if(30081001 == val){//保存
            this.loadingFlag1 = true;
            let result = await auditAdd(data);
            if (result.resultCode === 200) {
                this.$notify.success({title: '提示信息',message:'保存成功!'});
                this.loadingFlag1 = false;
                this.closeDialog('refresh');

            } else {
                this.$notify.error({title: '提示信息',message:result.errMsg||'保存失败!'});
            }

        }else{//提交
            this.loadingFlag2 = true;
            let result = await auditAdd(data);
            if (result.resultCode === 200) {
                this.$notify.success({title: '提示信息',message:'提交成功!'});
                this.loadingFlag2 = false;
                this.closeDialog('refresh');

            } else {
                this.$notify.error({title: '提示信息',message:result.errMsg||'提交失败!'});
            }

        }
    },
    closeDialog(val){//关闭弹框
      this.$emit('close')
    },
    createdFrom(){
      return [
        {
            type: 'INPUT',
            label: '票号',
            fieldName: 'paymentNo',
            rules: [
                {
                    required: true,
                    message: '请填写票号',
                    trigger: 'blur'
                }
            ]
        },
        {
            type: 'INPUT_NUMBER',
            label: '打款金额',
            fieldName: 'amount',
            precision:2,
            rules: [
                { 
                    required: true,
                    message: '请输入打款金额', 
                    trigger: 'blur' 
                },
                {
                    validator: plus, 
                    message: '打款金额格式不正确', 
                    trigger: 'blur' 
                }
            ],
        },
        {
            type: 'SELECT',
            label: '款项类型',
            fieldName: 'paymentType',
            placeholder: '请选择',
            itemList: this.createDictList('3007'),
            rules: [
                {
                    required: true,
                    message: '请选择款项类型',
                    trigger: 'blur'
                }
            ]
        },
        {
            type: 'SELECT',
            label: '打款方式',
            fieldName: 'paymentWay',
            placeholder: '请选择',
            itemList: this.createDictList('3009'),
            rules: [
                {
                  required: true,
                  message: '请选择打款方式',
                  trigger: 'blur'
                }
            ]
        },
        {
          type: 'DATE',
          label: '打款日期',
          fieldName: 'remitDate',
          placeholder: '请输入',
          format:'yyyy-MM-dd',
          rules: [
            {
              required: true,
              message: '请选择打款日期',
              trigger: 'blur'
            }
          ]
        },
        {
            type: 'INPUT',
            label: '打款人',
            fieldName: 'paymentPerson'
        },
        {
            type: 'INPUT',
            label: '收款银行',
            fieldName: 'bank'
        },
        {
            type: 'TEXT_AREA',
            label: '摘要',
            fieldName: 'content',
            placeholder: '请输入',
            selfCols:2,
            maxlength:150
        },
        {
            selfCols: 3,
            type: 'UPLOAD_FILE',
            label: '上传文件',
            fieldName: 'uploadFile',
            placeholder: '上传文件...',
            // rules: [{ required: true, message: '请上传文件', trigger: 'change' }],
            initialValue: '',
            upload: {
                actionUrl: '/api/file/oss/upload',
                limit: 1,
                tipText: '（支持：PDF、RAR、JPG格式）'
            }
        }
      ]
    }
  },

}
</script>
